import { graphql } from 'graphql'
import data from './graphqlData.js' //测试数据-实际不需要 为后台接口返回
let cashData = []
const handleData = path => {
  let dataSet = cashData.find(item => item.path == path)
  store.commit('setDataSet', dataSet)
}

// 数据初始化
const init = (path = '/') => {
  if (cashData.length != 0) {
    handleData(path)
  } else {
    let query = `{
      hello(name:"test"),
      person(name:"test"){
        name,
        sex,
        age
      }
    }`
    graphql(data, query).then(res => {
      console.log(res)
      // cashData=[...res]
      // app.$emit('dataReady')
    })
  }
  app.log('graphql init')
}
const destroy = () => {
  cashData = []
  app.log('graphql destroy')
}
export { init, destroy }
